<template>
  <div class='table'>
    <ui-container style="width:100%">
      <div class='t_top'>
        <el-date-picker
          v-model="PayDate"
          @change="getSTime"
          type="month"
           size="small"
          format="yyyy-MM"
          value-format="yyyy-MM"
          placeholder="账单季度">
        </el-date-picker>
        <el-button type="primary" size="small" @click="init()" >查询</el-button>
      </div>
    </ui-container>
    <ui-container style='margin-top:15px' v-loading="loading">
      <div class='t_bottom' style="width:100%; font-size:14px;">
        <el-table
          ref='multipleTable'
          :data='tableData'
          tooltip-effect='light'
          style='width:100%'
          border
        >
          <el-table-column prop='PayDate' label='账单季度' width='150' ></el-table-column>
          <el-table-column prop='TypeStr' label='账单类型' width='150' ></el-table-column>
          <el-table-column prop='UnitPrice' label='单价' width='120'></el-table-column>
          <el-table-column prop='Area' label='面积' width='100'></el-table-column>
          <el-table-column prop='TotalFee' label='总费用' width='120'></el-table-column>
          <el-table-column prop='LastDateStr' label='最后付款日期' width='140' ></el-table-column>
          <el-table-column prop='IsPay' label='是否已付款' width='100'>
            <template slot-scope="scope">
              <span>{{scope.row.IsPay?'是':'否'}}</span>
            </template>
          </el-table-column>
          <el-table-column prop='Remarks' label='备注' show-overflow-tooltip></el-table-column>
        </el-table>
        <div class="pagination-row">
          <el-pagination
            background
            layout="total,prev, pager, next,sizes"
            :total="totalNum">
          </el-pagination>
        </div>
      </div>
    </ui-container>
  </div>
</template>
<script type='text/javascript'>
import {cookieStorage} from 'src/common/storage'
export default {
  name: 'shopCouponList',
  data () {
    return {
      typeList:[{
          value: 0,
          label: '满减优惠券'
        }, {
          value: 1,
          label: '代金券'
        }],
      ShopCouponNumber:'',
      type: null,
      loading: false,
      tableData: [],
      totalNum:0,
      pageIndex:1,
      pageSize:10,
      PayDate:''
    }
  },
  mounted () {
    let myDate = new Date();
    let tYear = myDate.getFullYear();
    let tMonth = myDate.getMonth() +1;
    if(tMonth<10){
      tMonth = '0'+tMonth
    }
    //this.PayDate = tYear+'-'+tMonth
    this.init();
  },
  methods: {
    getSTime(val) {
      console.log(val)
        this.PayDate=val;//这个sTime是在data中声明的，也就是v-model绑定的值
    },
    search(){
      this.pageIndex = 1;
      this.init();
    },
    init(){
      this.loading=true;
      console.log(this.PayDate)
      var data = {
          PayDate: this.PayDate,
          PageIndex: this.pageIndex,
          PageSize: this.pageSize
        };

      this.$api.shop.companyBill(data).then((rs) => {
        console.log(rs)
        this.tableData = rs.Data.Data;
        this.totalNum = rs.Data.TotalNum;
        this.loading=false;
      }).catch((res) =>{this.loading=false;})
    },
    enable(index) {
      this.$confirm('核销该优惠券?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$api.shop.enable(index).then((rs) => {
        if(rs.IsSuccess){
          this.$message({
            type: 'success',
            message: '核销成功'
          });
          this.init();
          }
        }).catch((res) =>{})
      }).catch(() => {
        // this.$message({
        //   type: 'info',
        //   message: '已取消删除'
        // });
      });
    },
  }
}
</script>
<style lang='scss' type='text/scss' rel='stylesheet/scss'>
.container-main{
  width: 100% !important;
}
.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>
